import * as mongoose from 'mongoose';

export const allowEmptyArrayValidator = [
  function (val) {
    return true;
  },
  '',
];

export const LcProjectSchema = new mongoose.Schema(
  {
    type: String,
    theme: String,
    title: String,
    icon: String,
    description: { type: String, required: false },
    path: String,
    hash: String,

    cssPath: String,
    cssHash: String,
    cssUpdateAt: Number,

    width: Number,
    height: Number,
    screenshot: {
      type: mongoose.Schema.Types.Mixed,
      required: false,
    },
    folder: { type: String, required: false },
    schema: Object,
    documents: {
      type: mongoose.Schema.Types.Mixed,
      required: false,
    },
    packages: {
      type: mongoose.Schema.Types.Mixed,
      required: false,
    },

    envInfo: Object,
    appConfig: Object,
    storeInfo: Object,

    isTemplate: Number,
    templateTags: {
      type: mongoose.Schema.Types.Mixed,
      required: false,
    },

    themes: {
      type: mongoose.Schema.Types.Mixed,
      required: false,
    },

    modules: {
      type: mongoose.Schema.Types.Mixed,
      required: false,
    },

    scenes: {
      type: mongoose.Schema.Types.Mixed,
      required: false,
    },

    plugins: {
      type: mongoose.Schema.Types.Mixed,
      required: false,
    },
    assets: {
      type: mongoose.Schema.Types.Mixed,
      required: false,
    },
    canvas: {
      type: mongoose.Schema.Types.Mixed,
      required: false,
    },

    deleteAt: Number,
    deleteBy: Number,

    followUserIds: {
      type: mongoose.Schema.Types.Mixed,
      required: false,
    },
    member: {
      type: mongoose.Schema.Types.Mixed,
      required: false,
    },
    isPublic: Boolean,
    allowCopy: Boolean,
    allowCopyRole: String,

    // 🆕 公开访问配置
    publicIdentifier: String,
    publicEnabledAt: Number,
    publicEnabledBy: Number,

    // 🆕 自定义域名配置
    customDomain: {
      type: mongoose.Schema.Types.Mixed,
      required: false,
    },

    lastUpdateBy: Number,

    teamId: Number,
    userId: Number,
    create_time: Number,
    update_time: Number,
  },
  { validateBeforeSave: false },
);

export const LcDocumentSchema = new mongoose.Schema({
  type: String,
  frames: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  clients: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  portal: Boolean,
  onlySave: Boolean,
  projectId: mongoose.SchemaTypes.ObjectId,
  title: String,
  description: String,
  screenshot: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  poster: String,
  fileName: String,
  icon: String,
  folder: String,
  folderPath: String,
  schema: Object,
  cssPath: String,
  cssHash: String,
  cssUpdateAt: Number,
  from: Object,
  route: Object,
  types: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  packages: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  componentsMap: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  componentsRoot: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  assets: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  utilsMap: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  width: Number,
  height: Number,
  backgroundColor: String,

  pageConfig: Object,

  configure: Object,
  componentMeta: Object,

  branch: String,

  share: Boolean,
  scene: String,
  childScene: String,
  trade: String,
  childTrade: String,

  tags: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },

  path: String,
  hash: String,

  teamId: Number,
  userId: Number,
  lastUpdateBy: Number,
  create_time: Number,
  update_time: Number,
});

export const LcDocumentBackupSchema = new mongoose.Schema({
  data: Object,
  docId: mongoose.SchemaTypes.ObjectId,
  projectId: mongoose.SchemaTypes.ObjectId,
  teamId: Number,
  userId: Number,
  type: String,
  createAt: Number,
});
